package top.chenyaohua.init.imp;

import com.google.auto.service.AutoService;
import top.chenyaohua.init.InitExecution;
import top.chenyaohua.init.abstractInit.AbstractInitExecution;
import top.chenyaohua.utils.InitExecutionUtils;

import java.util.Iterator;
import java.util.List;
@AutoService(AbstractInitExecution.class)
public class DefaultInit extends AbstractInitExecution {

    public DefaultInit () {
        super(Integer.MIN_VALUE);
    }

    @Override
    public boolean init () {

        List<? extends InitExecution> initExecutions = InitExecutionUtils.get();
        Iterator<? extends InitExecution> iterator = initExecutions.iterator();

        while (iterator.hasNext()) {
            InitExecution next = iterator.next();
            if(next == this){
                //跳过本节点 直接进入第二个节点
                continue;
            }

            if ( !next.init() ) {
                break;
            }

        }

        return false;
    }
}
